package com.coolw.data.migrate.domain.response;

import com.coolw.common.api.BaseDomain;
import com.coolw.data.migrate.common.alarm.AlarmStatusEnum;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import org.dromara.hutool.core.text.StrUtil;

/**
 * 数据迁移结果
 *
 * @author coolw
 * @date 2024/2/1 16:54
 */
@Getter
@Setter
public class DataMigrateResponse extends BaseDomain {
    private static final long serialVersionUID = -5524913660860263599L;

    private static final String DEFAULT_SUCCESS_MESSAGE = "数据迁移成功";
    private static final String DEFAULT_FAIL_MESSAGE = "数据迁移失败";

    /**
     * 数据迁移结果标识
     */
    private Boolean success;

    /**
     * 源表名
     */
    private String sourceTableName;

    /**
     * 目标表名
     */
    private String targetTableName;

    /**
     * 预期迁移总数量
     */
    private Integer totalSize;

    /**
     * 迁移成功数量
     */
    private Integer successSize;

    /**
     * 迁移失败数量
     */
    private Integer failSize;

    /**
     * 耗时(毫秒)
     */
    private Long cost;

    /**
     * 数据迁移结果描述
     */
    private String message;

    /**
     * 告警状态
     */
    @JsonIgnore
    private AlarmStatusEnum alarmStatusEnum;

    public static DataMigrateResponse success(String message, Long cost) {
        DataMigrateResponse response = new DataMigrateResponse();
        response.setSuccess(Boolean.TRUE);
        response.setMessage(StrUtil.defaultIfBlank(message, DEFAULT_SUCCESS_MESSAGE));
        response.setCost(cost);
        return response;
    }

    public static DataMigrateResponse fail(String message) {
        return fail(message, null);
    }

    public static DataMigrateResponse fail(String message, Long cost) {
        DataMigrateResponse response = new DataMigrateResponse();
        response.setSuccess(Boolean.FALSE);
        response.setMessage(StrUtil.defaultIfBlank(message, DEFAULT_FAIL_MESSAGE));
        response.setCost(cost);
        return response;
    }
}
